package sunyu.tools.mongodb;

import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class MongoDbTools<T> {

    private static final int DEFAULT_SKIP = 0;
    private static final int DEFAULT_LIMIT = 10;
    @Resource(name = "mongoTemplate")
    private MongoTemplate mongoTemplate;

    public T save(T entity) {
        mongoTemplate.insert(entity);
        return entity;
    }

    public T findOne(Query query,
                     Class clazz) {
        return (T) mongoTemplate.findOne(query, clazz);
    }


}
